﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UniversityStudentManagemnetSystem.BLL;

namespace UniversityStudentManagemnetSystem.UI
{
    public partial class ViewAllOfficerPage : System.Web.UI.Page
    {
        OfficerManager manager=new OfficerManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack != true)
            {
                searchButton.Enabled = false;
                searchButton.Visible = false;

            }
        }

        protected void DesignationRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            PopulatedDesignationDropDownList();
            allRadioButton.Checked = false;
            allRadioButton.Text = string.Empty;
            searchButton.Visible = true;
            searchButton.Enabled = true;
        }

        private void PopulatedDesignationDropDownList()
        {
            DesignationManager designationManager = new DesignationManager();
            DataTable designations = designationManager.GetAllOfficerDesignations();
            designationDropDownList.DataTextField = "Name";
            designationDropDownList.DataValueField = "Id";
            designationDropDownList.DataSource = designations;
            designationDropDownList.DataBind();
        }

        protected void allRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            searchButton.Visible = false;
            PopulatedAllRadioButton();
        }
        private void PopulatedAllRadioButton()
        {
            designationRadioButton.Checked = false;
            designationRadioButton.Text = string.Empty;
            GetAllOfficer();


        }

        private void GetAllOfficer()
        {
            DataTable allEmployeeTable = manager.GetAllEmployee();
            officerGridView.DataSource = allEmployeeTable;
            officerGridView.DataBind();
        }

        protected void searchButton_Click(object sender, EventArgs e)
        {
            int selectedDesignation = Convert.ToInt32(designationDropDownList.SelectedValue);
            DataTable table = manager.GetAllOfficerDesignation(selectedDesignation);
            officerGridView.DataSource = table;
            officerGridView.DataBind();
        }

        protected void PersonalSearchLinkButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("PersonalOfficerInfomationPage.aspx");
        }
    }
}